<?php
class Web_View_Helper_CommerceStatus
	extends Zend_View_Helper_Abstract 
{
	
	public function commerceStatus( $negocio ) 
	{
//		$estado = $negocio->checkEstado(); 
//		
//		switch($estado){
//		
//		    case 1:
//		        $status = 'statusOpen';
//				$text	= $this->view->translate('open');
//		        break;
//		        
//		    case 2:
//		        $status = 'statusOpeningSoon';
//				$text = sprintf(	$this->view->translate('openToday'), 
//										$desde->toString(Zend_Date::TIME_SHORT)
//									);
//		        break;  
//
//            case 3:
//		        $status = 'statusDisconnected';
//				$text	= $this->view->translate('alreadyClosed');
//		        break;
//				    
//		        
//		    default:
//		        $status = 'statusDisconnected';
//				$text	= $this->view->translate('disconnected');
//		        break;
//		
//		}
		
		
		
		$status = 'statusDisconnected';
		$text	= $this->view->translate('disconnected');
		
		if ($negocio->estaAbierto()){
		
			if ($negocio->estaOnline()){
				
				$status = 'statusOpen';
				$text	= $this->view->translate('open');
				
			} elseif( $negocio->abreHoy()){
					
					
				$horariosHoy = $negocio->horariosHoy();
				
				$now = new Zend_Date();
				
//				$text	= $this->view->translate('alreadyClosed');
				
				foreach($horariosHoy as $horarioHoy){
				
					$desde = $horarioHoy->desde();
					
					if( $now->isEarlier( $desde )){
						
						$status = 'statusOpeningSoon';
						$text = sprintf(	$this->view->translate('openToday'), 
										$desde->toString(Zend_Date::TIME_SHORT)
									);
						break;
					} elseif( $now->isLater( $horarioHoy->hasta() ) ) {
						$text	= $this->view->translate('alreadyClosed');
					}
				
				}
		
			}
		}
		
		return "<p class='status {$status}'>{$text}</p>";
	}

}